<template>
  <div class="hello">
    <input v-model="inputText" placeholder="请输入内容" class="input-box" />
    <div v-if="inputText" class="output-box">{{ inputText }}</div>
    <button @click="clearInput" class="clear-button">清空</button>
  </div>
</template>

<script>
export default {
  name: 'HelloWorld',
  data() {
    return {
      inputText: ''
    };
  },
  methods: {
    clearInput() {
      this.inputText = '';
    }
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.input-box {
  width: 200px;
  height: 30px;
  padding: 0 10px;
  margin-bottom: 10px;
}
.output-box {
  padding: 10px;
  margin-bottom: 10px;
}
.clear-button {
  width: 80px;
  height: 30px;
  display: block; /* 强制按钮独占一行，放到文本框下面 */
  margin: 10px auto 0; /* 增加顶部间距，若有全局样式冲突，通过!important覆盖 */
}
h3 {
  margin: 40px 0 0;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>